//
//  MVVMViewModel.m
//  DebugDemo
//
//  Created by XFB on 2019/1/8.
//  Copyright © 2019年 ZhouCheng. All rights reserved.
//

#import "MVVMViewModel.h"
#import "MVVMModel.h"

@implementation MVVMViewModel

- (instancetype)init
{
    self = [super init];
    if (self) {
    }
    return self;
}

/// tableView头部刷新的网络请求
- (void)headerRefreshRequestWithCallBack:(CallBack)callBack
{
    /// 后台执行
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        sleep(2);
        dispatch_async(dispatch_get_main_queue(), ^{
           /// 回到主线程刷新UI
            NSMutableArray *array = @[].mutableCopy;
            for (NSInteger i = 0; i < 16; i ++) {
                NSInteger x = arc4random() % 100;
                
                NSString *string = [NSString stringWithFormat:@"%ld, 等你回家，才叫过年！", x];
                MVVMModel *model = [[MVVMModel alloc] init];
                model.title = string;
                [array addObject:model];
            }
            callBack(array);
        });
    });
}

/// tableView底部刷新的网络请求
- (void)footerRefreshRequestWithCallBack:(CallBack)callBack
{
    /// 后台执行 全部并发队列
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        sleep(2);
        dispatch_async(dispatch_get_main_queue(), ^{
           /// 回到主线程刷新UI
            NSMutableArray *array = @[].mutableCopy;
            for (NSInteger i = 0; i < 16; i ++) {
                NSInteger x = arc4random() % 100;
                
                NSString *string = [NSString stringWithFormat:@"%ld, 等你回家，才叫过年！", x];
                MVVMModel *model = [[MVVMModel alloc] init];
                model.title = string;
                [array addObject:model];
            }
            callBack(array);
        });
    });
}

@end
